﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace zielonka.co.uk.extensions.system.collections
{
    //Description: Combines parts of 2 byte arrays.
    /*
        byte[] arr1 = { 0x01, 0x02, 0x03, 0x04 };
        byte[] arr2 = { 0x05, 0x06, 0x07, 0x08 };

        byte[] arr3 = arr1.Combine(1, 3, arr2, 2, 2);
        //arr3 should be { 0x02, 0x03, 0x04, 0x07, 0x08 }

    */

    public static partial class ArrayExtensions
    {
        //.Net Framework, .Net Compact Framework, Silverlight
        public static byte[] CombineByteArrays(this byte[] src1, int offset1, int count1, byte[] src2, int offset2, int count2)
        {
            byte[] arr = new byte[count1 + count2];
            for (int i = 0; i < count1; i++)
                arr[i] = src1[offset1 + i];
            for (int i = 0; i < count2; i++)
                arr[count1 + i] = src2[offset2 + i];
            return arr;
        }

        ////.Net Micro Framework
        //public static byte[] CombineByteArrays(this byte[] src1, int offset1, int count1, byte[] src2, int offset2, int count2)
        //{
        //    return Microsoft.SPOT.Hardware.Utility.CombineArrays(src1, offset1, count1, src2, offset2, count2);
        //}
    }
}
